<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" import="java.sql.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>


<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Chi tiết sản phẩm</title>

<script src="http://code.jquery.com/jquery-latest.js">
</script>

<script>

	$(document).ready(

		function()
		{
			$("#add").click(
				function(){
						var service_id = $("select option:selected").text();
// 						var service_id = $('#service_id').find(":selected").text();
// 						var service_id = $("#service_id:selected").text();
						$.post('sql_serviceusing_add.jsp',{service_id:service_id},function(divtest)
						{
							$("#divtest").text(divtest);
						});
				}
			);
		}		
	);

</script>

</head>
<body bottomMargin=0 leftMargin=0
topMargin=0 rightMargin=0>
	<TABLE width="1024" height="768" border=0 cellSpacing=0 cellPadding=0 align=center>
	<TR HEIGHT="150">
	<TD Align=center colspan=5>
	<%@include file="../top.jsp"%>
	</TD>
	</TR>
	
	<!---Khai báo khoảng phân cách--->
	<TR HEIGHT="2">
	<TD colspan=5 bgcolor="white"></TD>
	</TR>
	
	<TR HEIGHT=100%>
	<TD vAlign="top" width="150">
	<%@include file="../left.jsp"%>
	</TD>
	
	<!---Khai báo khoảng phân cách--->
	<TD bgcolor=white width="2"></TD>
	
	<TD vAlign=top width="720" bgcolor=white>
		
	<%
		Class.forName("com.mysql.jdbc.Driver");
		Connection con = null;
		Statement smt = null;
		ResultSet rst = null;
		String customer_card = "";
		String customer_name= "";
		String customer_address = "";
		String date = "2014-01-01 00:00:00.0";
		String price_1 = "";
		String price_2 = "";
		String price_3 = "";
		String number = "";
		
		out.println("<table width=100% height=100% border=0>");
		try {
			String username = "root";
			String password = "Vietyeutam1112";
			String room_id = request.getParameter("room_id");
// 			String buyOK = request.getParameter("buy");
// 			System.out.println(buyOK);
			String url = "jdbc:mysql://127.0.0.1:3306/ghmotel";
			con = DriverManager.getConnection(url, username, password);
			System.out.println("Da ket noi CSDL");
			smt = con.createStatement();
			rst = smt.executeQuery("CALL getRoomInfo("+room_id+")");
			
			while (rst.next()){
				customer_card = rst.getString(1);
				date = rst.getString(3);
				price_1 = rst.getString(5);
				price_2 = rst.getString(6);
				price_3 = rst.getString(7);
				number = rst.getString(4);
			}
			
			Statement st = con.createStatement();
			ResultSet rs = st.executeQuery("CALL getCustomerInfo("+room_id+")");
			
			while (rs.next()) {
				customer_card = rs.getString(1);
				customer_name = rs.getString(2);
				customer_address = rs.getString(3);
			}
			
			Statement st4 = con.createStatement();
			ResultSet rs4 = st4.executeQuery("select * from customer");
			
			out.println("<form action=sql_ru_edit.jsp method=POST>");
			out.println("<table width=1024 align=center>");
			out.println("<tr></tr><tr></tr><tr></tr><tr><td width=1024 align='center' colspan=2><a id='a' href='service_emanager.jsp'>Quay về danh sách phòng</a><br><br></td></tr>");
			out.println("<tr><td width=30% align=right>Tên phòng </td>");
			out.println("<td width=70% align=left><input name=room_id type=text size=50 value='"+room_id+"'></td></tr>");
			out.println("<tr><td width=30% align=right>Số CMND khách hàng</td>");
			out.println("<td><select name=customer_card>");
			out.println("<option value='"+customer_card+"'>"+customer_name+"</option>");
			while (rs4.next()) {
				out.println("<option value='"+rs4.getString(1)+"'>"+rs4.getString(2)+"</option>");
			}
			out.println("</select></td>");
// 			out.println("<td width=70% align=left><input name=customer_card type=text size=50 value='"+customer_card+"'></td></tr>");
			//out.println("<tr><td width=30% align=right>Tên khách hàng</td>");
			//out.println("<td width=70% align=left><input name=customer_name type=text size=50 value='"+customer_name+"'></td></tr>");
			//out.println("<tr><td width=30% align=right>Địa chỉ khách hàng </td>");
			//out.println("<td width=70% align=left><input name=customer_address type=text size=50 value='"+customer_address+"'></td></tr>");
			out.println("<tr><td width=30% align=right>Số lượng người</td>");
			out.println("<td width=70% align=left><input name=number type=text size=50 value='"+number+"'></td></tr>");
			out.println("<tr><td width=30% align=right>Thời gian vào</td>");
			out.println("<td width=70% align=left><input name=in_date type=text size=50 value='"+date+"'></td></tr>");
			out.println("<tr><td width=30% align=right>Giá tiền cho 1 ngày</td>");
			out.println("<td width=70% align=left><input name=price_1 type=text size=50 value='"+price_1+"'></td></tr>");
			out.println("<tr><td width=30% align=right>Giá tiền cho 1 giờ đầu tiên</td>");
			out.println("<td width=70% align=left><input name=price_2 type=text size=50 value='"+price_2+"'></td></tr>");
			out.println("<tr><td width=30% align=right>Giá tiền mỗi giờ bonus</td>");
			out.println("<td width=70% align=left><input name=price_3 type=text size=50 value='"+price_3+"'></td></tr>");
			
			out.println("<tr><td width=30% align=right>Dịch vụ</td>");
			out.println("<td><table border="+"1"+" width=500 align=left>");
			out.println("<tr><td width=20% align=left >Mã DV</td><td width=35% align=left>Tên dịch vụ</td>");
			out.println("<td width=20% align=left>Giá</td>");
			out.println("<td width=20% align=left>Số lượng</td></tr>");
			
			Statement st2 = con.createStatement();
			ResultSet rs2 = st2.executeQuery("CALL getService_Using("+room_id+")");
			
			while (rs2.next()) {
				out.println("<tr><td width=20% align=left >"+rs2.getString(1)+"</td><td width=35% align=left>"+rs2.getString(2)+"</td>");
				out.println("<td width=20% align=left>"+rs2.getString(3)+"</td>");
				out.println("<td width=20% align=left>"+rs2.getString(4)+"</td></tr>");
			}
			
			out.println("</tr><tr>");
// 			out.println("<form action=sql_serviceusing_add.jsp>");
			out.println("<td><select name=service_id>");
			Statement st3 = con.createStatement();
			ResultSet rs3 = st3.executeQuery("SELECT * FROM service");
			while (rs3.next()) {
				out.println("<option value="+rs3.getString(1)+">"+rs3.getString(2)+"</option>");
// 				out.println("<option selected=selected value=123123>1</option>");
			}
			out.println("<div id=divtest></div>");
			out.println("</select>");
			out.println("<td><input type=button id=add value=Thêm></td>");
// 			out.println("</form>");
			
			out.println("</table></td> </tr>");
			out.println("<tr><td></td><td width=10% align=left><input type=submit value=Xong></td></tr>");
			out.println("<tr><td></td><td><a href=sql_tra_phong.jsp?room_id="+room_id+">Trả phòng</a></td></tr>");
			out.println("</table>");
			out.println("</form>");
		}		
		catch (Exception e) {}
		out.println("</table>");
			
	%>
	</TD>
	
	<!---Khai báo khoảng phân cách--->
	<TD bgcolor=white width="2"></TD>
	<TD vAlign=top width="150">
	<%@include file="../right.jsp"%>
	</TD>
	</TR>
	
	<!---Khai báo khoảng phân cách--->
	<TR HEIGHT="2">
	<TD colspan=5 bgcolor=white></TD>
	</TR>
	
	<TR HEIGHT="50">
	<TD colspan=5 align=center>
	<%@include file="../bottom.jsp"%>
	</TD>
	</TR>
	</TABLE>
</body>

</body>
</html>